#include "mainwindow.h"
#include "websocketclientwrapper.h"
#include "websockettransport.h"
#include "datatunnel.h"

#include <QWebChannel>
#include <QApplication>
#include <QWebSocketServer>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWebSocketServer server(QStringLiteral("QWebChannel Standalone Example Server"), QWebSocketServer::NonSecureMode);
    if (!server.listen(QHostAddress::LocalHost, 1591)) {
        qFatal("Failed to open web socket server.");
        return 1;
    }

    // wrap WebSocket clients in QWebChannelAbstractTransport objects
    WebSocketClientWrapper clientWrapper(&server);

    // setup the channel
    QWebChannel channel;
    QObject::connect(&clientWrapper, &WebSocketClientWrapper::clientConnected,
                     &channel, &QWebChannel::connectTo);

    channel.registerObject(QStringLiteral("dataTunnel"), DataTunnel::instance());

    MainWindow w;
    w.show();

    return a.exec();
}
